app.controller('gradeSearchCtrl', function($scope, $stateParams, $http,$ionicLoading) {
    //用户数据
    var user_info = JSON.parse(localStorage.getItem("UserInfo"));
    //项目路径
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    $scope.hasMore = true;
    var currentPageNum = 1;
    var totalCount = 0;
    var obj = {userId:user_info.userId,currentPage:currentPageNum,pageSize:10};
    $scope.noteList = [];
    angular.element(document).ready(function () {
        $scope.loadMore();
    })
    //检测到达到页面底部，自动执行loadMore方法
    $scope.loadMore = function(){
        chushihua(obj);
        obj.currentPage=currentPageNum++;
        $scope.$broadcast('scroll.infiniteScrollComplete');
    };

    //点击搜索按钮
    $scope.doRefresh = function(getExamName){
        $scope.hasMore = true;
        currentPageNum = 1;
        obj = {userId:user_info.userId,examName:getExamName,currentPage:currentPageNum,pageSize:10};
        $scope.noteList = [];
            // chushihua(obj);
            // $scope.$broadcast('scroll.infiniteScrollComplete');
    };

    function chushihua(obj_data){
            var url = getPath.url+getPath.name+"/app/findUserExamScore";
            $http({
                method:"POST",
                url:url,
                data:obj_data,
                headers:{'Content-Type':'application/x-www-form-urlencoded'},
                dataType:'JSON'
            }).success(function(data) {
                totalCount = data.pageCond.totalCount;
                var res = data.resultList;
                for(var i=0;i<res.length;i++){
                    if(res[i].examName.length>10){
                        res[i].examName = res[i].examName.substr(0,10)+"...";
                    }
                }
                Array.prototype.push.apply($scope.noteList, data.resultList);
            }).error(function(data) {
                $scope.hasMore = false;
                if(($scope.noteList.length==totalCount)&&(currentPageNum>3)){
                    $ionicLoading.show({
                        template: "没有更多内容了！",
                        duration:3000
                    });
                }
            });

    }
})